package com.batata.continuing.web.user;

import com.batata.continuing.config.count.ip.IpMax;
import com.batata.continuing.config.moreNote.token.NotNeedToken;
import com.batata.continuing.pojo.base.ResultData;
import com.batata.continuing.pojo.user.UserInfo;
import com.batata.continuing.service.user.UserService;
import com.batata.continuing.service.user.impl.UserServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户相关接口
 */
@Api(tags = "用户相关接口")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private UserServiceImpl userServiceImpl;

    @IpMax(count = 3, time = 10)
    @NotNeedToken
    @ApiOperation("查询用户的数量")
    @PostMapping("/getUserCount")
    public long getUserCount() {
        return userService.getUserCount();
    }

    @NotNeedToken
    @ApiOperation("是否存在 loginName true 存在 false 不存在 ")
    @PostMapping("/isHaveByLoninName")
    @ApiImplicitParam(name = "loginName", value = "账号", required = true, dataType = "String")
    public boolean isHaveByLoninName(String loginName) {
        return userServiceImpl.isHaveByLoninName(loginName);
    }

    @NotNeedToken
    @ApiOperation("是否存在 phoneNumber true 存在 false 不存在 ")
    @PostMapping("/isHaveByPhoneNumber")
    @ApiImplicitParam(name = "phoneNumber", value = "密码", required = true, dataType = "String")
    public boolean isHaveByPhoneNumber(String phoneNumber) {
        return userServiceImpl.isHaveByPhoneNumber(phoneNumber);
    }


    @NotNeedToken
    @ApiOperation("创建新的用户")
    @PostMapping("/createUser")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "loginName", value = "账号", required = true, dataType = "String"),
            @ApiImplicitParam(name = "loginPassword", value = "密码", required = true, dataType = "String")
    })
    public ResultData<?> createUser(UserInfo userInfo) {
        return userServiceImpl.createUser(userInfo);
    }


    @NotNeedToken
    @ApiOperation("测试查询")
    @PostMapping("/selectTest")
    public  ResultData<?> selectTest() {
        return userServiceImpl.selectTest();
    }


}
